﻿<Window x:Class="SchoolClient.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:syncfusion="http://schemas.syncfusion.com/wpf" 
    xmlns:sf="clr-namespace:Syncfusion.Windows.Controls.Grid;assembly=Syncfusion.Grid.Wpf"
    xmlns:sfs="clr-namespace:Syncfusion.Windows.Shared;assembly=Syncfusion.Shared.Wpf"
    xmlns:wt="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit"    
    xmlns:local="clr-namespace:SchoolClient"
    xmlns:domain="clr-namespace:SchoolDomain;assembly=SchoolDomain"
    sfs:SkinStorage.VisualStyle="Default" Style="{StaticResource windowStyle}" Height="400" Width="600">
    <Window.Title>
        <Binding Path="DatabaseName" Source="{x:Static domain:Domain.Instance}" >
            <Binding.Converter>
                <local:WindowTitleConverter />
            </Binding.Converter>
        </Binding>
    </Window.Title>
    <Window.CommandBindings>
        <CommandBinding Command="local:MainWindow.newJournalCommand" Executed="NewJournal_Executed" />
        <CommandBinding Command="local:MainWindow.openJournalCommand" Executed="OpenJournal_Executed" />
        <CommandBinding Command="local:MainWindow.saveJournalCommand" Executed="SaveJournal_Executed" />
        <CommandBinding Command="local:MainWindow.saveAsJournalCommand" Executed="SaveAsJournal_Executed" />
        <CommandBinding Command="local:MainWindow.addUnitCommand" Executed="AddUnit_Executed" />
        <CommandBinding Command="local:MainWindow.deleteUnitCommand" Executed="DeleteUnit_Executed" />
        <CommandBinding Command="local:MainWindow.applicationQuitCommand" Executed="ApplicationQuit_Executed" />
    </Window.CommandBindings>
    <Window.InputBindings>
        <KeyBinding Command="local:MainWindow.newJournalCommand" Key="N" Modifiers="Ctrl" />
        <KeyBinding Command="local:MainWindow.openJournalCommand" Key="O" Modifiers="Ctrl" />
        <KeyBinding Command="local:MainWindow.saveJournalCommand" Key="S" Modifiers="Ctrl" />        
    </Window.InputBindings>
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/Syncfusion.Shared.WPF;component/SkinManager/SkinManager.xaml"/>
            </ResourceDictionary.MergedDictionaries>
            <local:BoolVisibilityConverter x:Key="BoolVisibilityConverter" />
            <local:StandardMarkConverter x:Key="StandardMarkConverter" />
            <local:AverageMarkConverter x:Key="AverageMarkConverter" />
            <local:RatingConverter x:Key="RatingConverter" />
            <local:WindowTitleConverter x:Key="WindowTitleConverter" />
            <ContextMenu x:Key="paramContextMenu" Opened="ContextMenu_Opened" Closed="ContextMenu_Closed">
                <MenuItem Header="Отлично" IsCheckable="True" 
                    IsChecked="{Binding Path=Tag.StandardMark, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}, Converter={StaticResource StandardMarkConverter}, ConverterParameter=5}"/>
                <MenuItem Header="Хорошо" IsCheckable="True" 
                    IsChecked="{Binding Path=Tag.StandardMark, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}, Converter={StaticResource StandardMarkConverter}, ConverterParameter=4}"/>
                <MenuItem Header="Удовлетворительно" IsCheckable="True" 
                    IsChecked="{Binding Path=Tag.StandardMark, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}, Converter={StaticResource StandardMarkConverter}, ConverterParameter=3}"/>
                <MenuItem Header="Неудовлетворительно" IsCheckable="True" 
                    IsChecked="{Binding Path=Tag.StandardMark, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}, Converter={StaticResource StandardMarkConverter}, ConverterParameter=2}"/>
                <Separator />
                <MenuItem Header="Дисциплинарное замечание" IsCheckable="True" 
                    IsChecked="{Binding Path=Tag.DisciplineNote, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}"/>
                <MenuItem Header="Деструктивный конфликт" IsCheckable="True" 
                    IsChecked="{Binding Path=Tag.DestructiveConflict, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}"/>
                <MenuItem Header="Творческая активность" IsCheckable="True"  
                    IsChecked="{Binding Path=Tag.CreativeActivity, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}"/>
                <MenuItem Header="Опоздение" IsCheckable="True" 
                    IsChecked="{Binding Path=Tag.BeingLate, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}"/>
                <MenuItem Header="Пропуск" IsCheckable="True" 
                    IsChecked="{Binding Path=Tag.Absence, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}"/>
            </ContextMenu>
            <ContextMenu x:Key="unitContextMenu" >
                <MenuItem Header="Добавить урок" Command="local:MainWindow.addUnitCommand" >
                    <MenuItem.Icon>
                        <Image Source="add-unit-16x16.png" Height="16" />
                    </MenuItem.Icon>    
                </MenuItem>
                <MenuItem Header="Удалить урок" Command="local:MainWindow.deleteUnitCommand" >
                    <MenuItem.Icon>
                        <Image Source="delete-unit-16x16.png" Height="16" />
                    </MenuItem.Icon>
                </MenuItem>
            </ContextMenu>
            <Popup x:Key="calendarPopup" Opened="Popup_Opened" Closed="Popup_Closed">
                <wt:Calendar SelectedDate="{Binding Path=Tag.UnitDate, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Popup}}}" />
            </Popup>
            <DataTemplate x:Key="MarkDataTemplate">
                <DockPanel LastChildFill="True" MouseRightButtonUp="Cell_MouseRightButtonUp">
                    <TextBlock Padding="2,0" Text="{Binding Path=CellValue.StandardMark}" />
                    <TextBlock Text="ДЗ" Visibility="{Binding Path=CellValue.DisciplineNote, Converter={StaticResource BoolVisibilityConverter}}"/>
                    <TextBlock Text="ДК" Visibility="{Binding Path=CellValue.DestructiveConflict, Converter={StaticResource BoolVisibilityConverter}}"/>
                    <TextBlock Text="ТА" Visibility="{Binding Path=CellValue.CreativeActivity, Converter={StaticResource BoolVisibilityConverter}}"/>
                    <TextBlock Text="О" Visibility="{Binding Path=CellValue.BeingLate, Converter={StaticResource BoolVisibilityConverter}}"/>
                    <TextBlock Text="Н" Visibility="{Binding Path=CellValue.Absence, Converter={StaticResource BoolVisibilityConverter}}"/>
                    <TextBlock />
                </DockPanel>
            </DataTemplate>
            <DataTemplate x:Key="AverageMarkDataTemplate">
                <TextBlock Padding="2,0" HorizontalAlignment="Center" Text="{Binding Path=CellValue.AverageMark, Converter={StaticResource AverageMarkConverter}}" />
            </DataTemplate>
            <DataTemplate x:Key="RatingDataTemplate">
                <TextBlock Padding="2,0" HorizontalAlignment="Center" Text="{Binding Path=CellValue.Rating, Converter={StaticResource RatingConverter}}" />
            </DataTemplate>
            <DataTemplate x:Key="HeaderTemplate">
                <DockPanel LastChildFill="True"  VerticalAlignment="Center" MouseRightButtonUp="DockPanel_MouseRightButtonUp" MouseLeftButtonUp="DockPanel_MouseLeftButtonUp">
                    <TextBlock TextAlignment="Center" Text="{Binding Path=CellValue}" />
                </DockPanel>
            </DataTemplate>
        </ResourceDictionary>
    </Window.Resources>
    <DockPanel LastChildFill="True">
        <Menu Name="mainMenu" DockPanel.Dock="Top">
            <MenuItem Header="Файл">
                <MenuItem Header="Создать журнал" Command="local:MainWindow.newJournalCommand" >
                    <MenuItem.Icon>
                        <Image Source="new-journal-16x16.png" />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Header="Открыть журнал" Command="local:MainWindow.openJournalCommand" >
                    <MenuItem.Icon>
                        <Image Source="open-journal-16x16.png" />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Header="Сохранить журнал" Command="local:MainWindow.saveJournalCommand" >
                    <MenuItem.Icon>
                        <Image Source="save-journal-16x16.png" />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Header="Сохранить журнал как..." Command="local:MainWindow.saveAsJournalCommand" >
                    <MenuItem.Icon>
                        <Image Source="save-journal-as-16x16.png" />
                    </MenuItem.Icon>
                </MenuItem>
                <Separator/>
                <MenuItem Header="Добавить урок" Command="local:MainWindow.addUnitCommand" >
                    <MenuItem.Icon>
                        <Image Source="add-unit-16x16.png" Height="16"/>
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Header="Удалить урок" Command="local:MainWindow.deleteUnitCommand">
                    <MenuItem.Icon>
                        <Image Source="delete-unit-16x16.png" Height="16"/>
                    </MenuItem.Icon>
                </MenuItem>    
                <Separator/>
                <MenuItem Header="Экспорт в Excel"/>
                <Separator />
                <MenuItem Header="Выход" Command="local:MainWindow.applicationQuitCommand"/>
            </MenuItem>
            <MenuItem Header="Сервис">
                <MenuItem Header="Параметры" />
            </MenuItem>
            <MenuItem Header="Справка">
                <MenuItem Header="О программе..." />
            </MenuItem>    
        </Menu>
        <ToolBar DockPanel.Dock="Top">
            <Button Name="addUnit" Margin="2,0,0,0" ToolTip="Добавить урок" Command="local:MainWindow.addUnitCommand">
                <Button.Content>
                    <StackPanel Orientation="Horizontal">
                        <Image Margin="2" Source="add-unit-32x32.png" Height="32" Width="32"/>
                        <TextBlock Margin="2" VerticalAlignment="Center">Добавить урок</TextBlock>
                    </StackPanel>
                </Button.Content>
            </Button>
            <Button Name="newJournal" Margin="2,0,0,0" ToolTip="Создать журнал" Command="local:MainWindow.newJournalCommand">
                <Image Margin="2" Source="new-journal-32x32.png" Height="32" Width="32"/>
            </Button>
            <Button Name="openJournal" Margin="2,0,0,0" ToolTip="Открыть журнал" Command="local:MainWindow.openJournalCommand">
                <Image Margin="2" Source="open-journal-32x32.png" Height="32" Width="32"/>
            </Button>
            <Button Name="saveJournal" Margin="2,0,0,0" ToolTip="Сохранить журнал" Command="local:MainWindow.saveJournalCommand">
                <Image Margin="2" Source="save-journal-32x32.png" Height="32" Width="32"/>
            </Button>
            <Button Name="saveAsJournal" Margin="2,0,0,0" ToolTip="Сохранить журнал как..." Command="local:MainWindow.saveAsJournalCommand">
                <Image Margin="2" Source="save-journal-as-32x32.png" Height="32" Width="32"/>
            </Button>
        </ToolBar>
        <StatusBar DockPanel.Dock="Bottom" Height="21"></StatusBar>
        <ScrollViewer CanContentScroll="True" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
            <sf:GridControl Name="grid" CurrentCellAcceptedChanges="grid_CurrentCellAcceptedChanges" ResizingRows="grid_ResizingRows">
            </sf:GridControl>        
        </ScrollViewer>
    </DockPanel>
</Window>
